(use-modules (gnu packages)
             (guix packages)
             (ice-9 match)
             (srfi srfi-1)
             (srfi srfi-26))

;;; Taken from common-input.scm.
(define* (package-all-inputs package #:key transitive?)
  (filter
   package?                             ;eliminate origin objects
   (map (match-lambda
          ((name package output ...)
           package))
        (delete-duplicates
         (remove null?
                 (if transitive?
                     (append (package-transitive-inputs package)
                             (package-transitive-native-inputs package)
                             (package-transitive-propagated-inputs package))
                     (append (package-inputs package)
                             (package-native-inputs package)
                             (package-propagated-inputs package))))))))

(define* (has-input? package input #:key (transitive? #t))
  "True if PACKAGE has INPUT among its dependency closure graph."
  (member input (package-all-inputs package #:transitive? transitive?)))

(define (run-example)
  ;; Find which package depends on fontconfig but not on librsvg.
  (let ((librsvg (specification->package "librsvg@2.40.21"))
        (fontconfig (specification->package "fontconfig")))
    (fold-packages (lambda (package result)
                     (if (and (has-input? package fontconfig)
                              (not (has-input? package librsvg)))
                         (cons package result)
                         result))
                   '())))
